package org.keyroy.map_editor.ui.component;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.swing.JComponent;

import org.keyroy.map_editor.map.bin.UIBin;

public class ImageComponet extends JComponent {
	private static final long serialVersionUID = 1L;

	private BufferedImage image;
	public int id;

	public ImageComponet(int id, BufferedImage bufferedImage, int width, int height) {
		if (bufferedImage.getWidth() > width || bufferedImage.getHeight() > height) {
			bufferedImage = UIBin.scaleImage(bufferedImage, width, height);
		}
		this.image = bufferedImage;
		this.id = id;
	}

	@Override
	public void paint(Graphics g) {
		g.setColor(Color.GRAY);
		g.drawImage(image, (getWidth() - image.getWidth()) / 2, (getHeight() - image.getHeight()) / 2, this);
		g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
	}
}
